**********************************************************************************************
//*SET USER*//
*Users Identification Code
*User 1
*User 2


//Set user below:
global user 1

//Enter the filepath of where the Master Folder is located//
*********************************************************
//User 1
if $user == 1 {
	global FH ""
}
**********************************************************
//User 2
if $user == 2 {

	global FH 
}
************************************************************
*************************PHILIPPINES************************
************************************************************
//GENERATING SCORES
do "$FH/do/Scores/PHL_HOC_Scores.do"

******************************************************************************************
//*RE-CLASSIFICATION OF BASELINE PARAMETERS*//

///CLASSIFICATION OF RETAIL TYPE INTO 3 NEW TYPES: "SARI-SARI STORE", "FOOD RETAIL" AND "NON-FOOD RETAIL"///

tab b_retailtype
tab b_retailtype, nol
gen b_retailtype_new = 1 if b_retailtype == 1
replace b_retailtype_new = 3 if b_retailtype == 8
replace b_retailtype_new = 2 if b_retailtype_new != 1 & b_retailtype_new != 3
tab b_retailtype_new
label variable b_retailtype_new "retail type revised classification"
label define retailnew 1"Sari-Sari Store" 2"Food Retail" 3"Non-Food Retail"
label values b_retailtype_new retailnew
tab b_retailtype_new
tab b_retailtype_new, nol
tab b_retailtype_new, gen(b_retailtype_new_)

*********************************************************************************
///RE-CLASSIFICATION OF EDUCATION INTO 4 LEVELS: "LESS THAN 5TH CLASS", "ABOVE 5TH CLASS", "COMPLETED HIGH SCHOOL" & "GRADUATE/POST-GRADUATE"///

tab b_education
tab b_education, nol
gen b_education_new = 1 if b_education <= 2
replace b_education_new = 2 if b_education == 3
replace b_education_new = 3 if b_education == 4
replace b_education_new = 4 if b_education >= 5
tab b_education_new
label variable b_education_new "revised education level"
label define educationnew 1"less than 5th class" 2"above 5th class" 3"complete high school" 4"graduate / post graduate"
label values b_education_new educationnew
tab b_education_new
tab b_education_new, nol
tab b_education_new, gen(b_education_new_)

//*GENERATING VARIABLES TO CAPTURE PERCENTAGES OF SAMPLE FOR CERTAIN VARIABLES*//
//Whether Business is Primary Source of Income
tab b_bus_prime
gen bal_bus_prime = 1 if b_bus_prime == 1
replace bal_bus_prime = 0 if b_bus_prime != 1
tab bal_bus_prime
label var bal_bus_prime "Business is Primary Source of Income"

//Cash Separation
tab b_cashseparate
gen bal_cashseparate = 1 if b_cashseparate == 1
replace bal_cashseparate = 0 if b_cashseparate != 1
tab bal_cashseparate
label var bal_cashseparate "Do Separate Business & Household Cash"

//Salary to Self
tab b_qd3_1_c
gen bal_selfsalary = 1 if b_qd3_1_c == 1
replace bal_selfsalary = 0 if b_qd3_1_c != 1
tab bal_selfsalary
label var bal_selfsalary "Do Pay Salary to Self"


//Calculation of Profits
tab b_profitcal
gen bal_profitcal = 0 if b_profitcal == 1
replace bal_profitcal = 1 if b_profitcal != 1
tab bal_profitcal
label var bal_profitcal "Do Calculate Profits"


//Give Customers Credit for at most 7 days
tab b_daygivecredit
gen bal_creditdays = 0 if b_daygivecredit <= 120
replace bal_creditdays = 1 if b_daygivecredit <= 7
tab bal_creditdays
label var bal_creditdays "Give customers credit for at most 7 days"


//Keep business records
tab b_keeprecord
gen bal_keeprecord = 1 if b_keeprecord == 1 | b_keeprecord == -777
replace bal_keeprecord = 0 if b_keeprecord == 0 | b_keeprecord == -888 | b_keeprecord == -999 
tab bal_keeprecord
label var bal_keeprecord "Keep Business Records"

//Record Customer Credit Record
tab b_cc4
gen bal_creditrecord = 1 if b_cc4 == 1
replace bal_creditrecord = 0 if b_cc4 == 0
tab bal_creditrecord
label var bal_creditrecord "Keep Customer Credit Records"

//Record Customer Credit Details
tab b_cc5
gen bal_creddetail = 1 if b_cc5 == 1
replace bal_creddetail = 0 if b_cc5 == 0
tab bal_creddetail
label var bal_creddetail "Keep customer credit details"


//Never Ran out of stock in the last 2 weeks
tab b_outofstock
gen bal_stockout = 1 if b_outofstock == 1
replace bal_stockout = 0 if b_outofstock != 1
tab bal_stockout
label var bal_stockout "Never Ran out of stock in the past 2 weeks"

//Good strategy to determine stock
tab b_im2
gen bal_goodstockstrat = 1 if b_im2 == 3
replace bal_goodstockstrat = 0 if b_im2 != 3
tab bal_goodstockstrat
label var bal_goodstockstrat "Determine stock based on a good strategy" 

//Never Visit competitors to check out goods 
tab b_visitcompet
gen bal_visitcompet = 1 if b_visitcompet == 7
replace bal_visitcompet = 0 if b_visitcompet != 7
tab bal_visitcompet
label var bal_visitcompet "Never Visit competitors to check prices/quality"

//Never Talk to customers to determine their needs
tab b_customertalk
gen bal_customtalk = 1 if b_customertalk == 6
replace bal_customtalk = 0 if b_customertalk != 6
tab bal_customtalk
label var bal_customtalk "Never Talk to customers to understand their needs"

//Introduced new product based on a good strategy
tab b_im5_adj
gen bal_goodnewstrat = 1 if b_im5_adj == 3
replace bal_goodnewstrat = 0 if b_im5_adj != 3
tab bal_goodnewstrat
label var bal_goodnewstrat "Introduced new products with a good strategy"

//Never do supplier quality comparison
tab b_comparesuppliers
gen bal_qualcomp = 1 if b_comparesuppliers == 7
replace bal_qualcomp = 0 if b_comparesuppliers != 7
tab bal_qualcomp
label var bal_qualcomp "Never do supplier quality comparison"

//Never Negotiate Prices with suppliers
tab b_negotiate
gen bal_negotiate = 1 if b_negotiate == 7 
replace bal_negotiate = 0 if b_negotiate != 7
tab bal_negotiate
label var bal_negotiate "Never Negotiated terms with suppliers"

//Ask Suppliers for Better Terms
tab b_askbetterterm
gen bal_betterterms = 1 if b_askbetterterm == 1
replace bal_betterterms = 0 if b_askbetterterm >= 2
tab bal_betterterms
label var bal_betterterms "Successfully Asked suppliers for better terms"

//Take advantage of cash discount
tab b_sm4
gen bal_cashdisc = 1 if b_sm4 == 1
replace bal_cashdisc = 0 if b_sm4 == 0 
tab bal_cashdisc
label var bal_cashdisc "Took full advantage of cash discount"

//Do nothing when customers do not pay credit
tab b_donothing
label var b_donothing "Do nothing when customers do not pay credit"

//Gender 
tab b_gender 
gen bal_gender = 1 if b_gender == 0
replace bal_gender = 0 if b_gender != 0
tab bal_gender

//Recoding Education into High School & Above
gen hs_above =. 
replace hs_above = 1 if b_education == 4 | b_education == 5 | b_education == 6
replace hs_above = 0 if hs_above == .
tab hs_above

******************************************************************************************
//*BALANCE TABLE*//

//ssc install ietoolkit

label var b_age "Age"
label var bal_gender "Female"
label var hs_above "High School or Above"
label var bal_bus_prime "Business is Primary Source of Income"
label var b_retailtype_new_2 "Retail: Food"
label var bal_cashseparate "Do Separate Business & Household Cash"
label var bal_selfsalary "Do Pay Salary to Self"
label var bal_profitcal "Do Calculate Profits"
label var b_cc5 "Record Important Customer Credit Information"
label var bal_creditdays "Give customers credit for at most 7 days"
label var b_donothing "Do nothing when customers do not pay credit"
label var bal_keeprecord "Keep Business Records "
label var bal_creditrecord "Keep Customer Credit Records"
label var bal_goodstockstrat "Determine stock based on a good strategy"
label var bal_visitcompet "Never Visit competitors to check prices/quality"
label var bal_customtalk "Never Talk to customers to understand needs"
label var bal_qualcomp "Never do supplier quality comparison"
label var bal_negotiate "Never Negotiated terms with suppliers "
label var bal_cashdisc "Took full advantage of cash discount"
label var w1b_salesregwk "Sales-Regular Week (Winsorized at 1%)"
label var w1b_profitregwk "Profits-Regular Week (Winsorized at 1%)"

///GENERATING BALANCE TABLE WITH BASELINE CHARACTERISTICS///
iebaltab b_age bal_gender hs_above bal_bus_prime b_retailtype_new_2 bal_cashseparate bal_selfsalary bal_profitcal bal_creditdays b_donothing bal_keeprecord bal_creditrecord b_cc5 bal_goodstockstrat bal_visitcompet bal_customtalk bal_qualcomp bal_negotiate bal_cashdisc w1b_salesregwk w1b_profitregwk, grpvar(tcarm) savet("$FH/tables/Table 1A.tex") total  rowvarlabels stats(desc(sd) pair(p)) totallabel(Total Sample) grouplabels("0 Control @ 1 Treatment") starlevels(0.1 0.05 0.01) texc("A: Summary Statistics and Balance-Philippines") addnote("Notes: This table presents summary statistics based on baseline survey data. Standard deviations (column 2, 3, 4) of variables and p-values (column 5) appear in parentheses. * Denotes significance at 10%-level, ** at the 5%-level, and *** at the 1%-level") texdoc texn(1.6) replace nonote

************************************************************
*************************INDIA******************************
************************************************************
//*SET DIRECTORY & LOAD DATA & GENERATE SCORES*//
clear
do "$FH/do/Scores/INDW1_HOC_Scores.do"

********************************************************************************************
//*RE-CLASSIFICATION OF BASELINE PARAMETERS*//

///CLASSIFICATION OF RETAIL TYPE INTO 3 NEW TYPES: "SHOP", "FOOD RETAIL" AND "NON-FOOD RETAIL"///
tab b_retailtype
tab b_retailtype, nol
gen b_retailtype_new = 1 if b_retailtype == 2
replace b_retailtype_new = 2 if b_retailtype == 1 | b_retailtype == 9 | b_retailtype == 11
replace b_retailtype_new = 3 if b_retailtype_new != 1 & b_retailtype_new != 2
replace b_retailtype_new = . if b_retailtype < 0
tab b_retailtype_new
label variable b_retailtype_new "Revised-Retail type classification"
label define retailnew 1"Shop" 2"Food Retail" 3"Non-food Retail"
label values b_retailtype_new retailnew
tab b_retailtype_new
tab b_retailtype_new, nol
tab b_retailtype_new, gen(b_retailtype_new_)

*********************************************************************************
///RE-CLASSIFICATION OF EDUCATION INTO 4 LEVELS: "LESS THAN 5TH CLASS", "ABOVE 5TH CLASS", "COMPLETED HIGH SCHOOL" & "GRADUATE/POST-GRADUATE"///

tab b_education
tab b_education, nol
gen b_education_new = 1 if b_education <= 2
replace b_education_new = 2 if b_education == 3
replace b_education_new = 3 if b_education == 4
replace b_education_new = 4 if b_education >= 5
replace b_education_new = . if b_education < 0
tab b_education_new
label variable b_education_new "Revised-Education Level"
label define educationnew 1"Less than 5th Grade" 2"Above 5th Glass" 3"Completed High School" 4"Graduate/Post-Graduate"
label values b_education_new educationnew
tab b_education_new
tab b_education_new, nol
tab b_education_new, gen(b_education_new_)

//Recoding Education into High School & Above
gen hs_above =. 
replace hs_above = 1 if b_education == 4 | b_education == 5 | b_education == 6
replace hs_above = 0 if hs_above == .
tab hs_above


******************************************************************************************
//*GENERATING VARIABLES TO CAPTURE PERCENTAGES OF SAMPLE FOR CERTAIN VARIABLES*//

//Whether Business is Primary Source of Income
tab b_bus_prime
gen bal_bus_prime = 1 if b_bus_prime == 1
replace bal_bus_prime = 0 if b_bus_prime != 1
tab bal_bus_prime
label var bal_bus_prime "Business is Primary Source of Income"

//Cash Separation
tab b_cashseparate
gen bal_cashseparate = 1 if b_cashseparate == 1
replace bal_cashseparate = 0 if b_cashseparate != 1
tab bal_cashseparate
label var bal_cashseparate "Do Separate Business & Household Cash"

//Salary to Self
tab b_qd3_1_c
gen bal_selfsalary = 1 if b_qd3_1_c == 1
replace bal_selfsalary = 0 if b_qd3_1_c != 1
tab bal_selfsalary
label var bal_selfsalary "Do Pay Salary to Self"


//Calculation of Profits
tab b_profitcal
gen bal_profitcal = 1 if b_profitcal == 1
replace bal_profitcal = 0 if b_profitcal != 1
tab bal_profitcal
label var bal_profitcal "Do Calculate Profits"


//Give Customers Credit for at most 7 days
tab b_daygivecredit
gen bal_creditdays = 0 if b_daygivecredit <= 120
replace bal_creditdays = 1 if b_daygivecredit <= 7
tab bal_creditdays
label var bal_creditdays "Give customers credit for at most 7 days"


//Keep business records
tab b_keeprecord
gen bal_keeprecord = 1 if b_keeprecord == 1 | b_keeprecord == 2
replace bal_keeprecord = 0 if b_keeprecord == 3 | b_keeprecord == -888
tab bal_keeprecord
label var bal_keeprecord "Keep Business Records"

//Record Customer Credit Record
tab b_cc4
gen bal_creditrecord = 1 if b_cc4 == 1
replace bal_creditrecord = 0 if b_cc4 == 0
tab bal_creditrecord
label var bal_creditrecord "Keep Customer Credit Records"

//Record Customer Credit Details
tab b_cc5
gen bal_creddetail = 1 if b_cc5 == 3
replace bal_creddetail = 0 if b_cc5 == 1
tab bal_creddetail
label var bal_creddetail "Keep customer credit details"


//Never Ran out of stock in the last 2 weeks
tab b_outofstock
gen bal_stockout = 1 if b_outofstock == 1
replace bal_stockout = 0 if b_outofstock != 1
tab bal_stockout
label var bal_stockout "Never Ran out of stock in the past 2 weeks"

//Good strategy to determine stock
tab b_im2
gen bal_goodstockstrat = 1 if b_im2 == 3
replace bal_goodstockstrat = 0 if b_im2 != 3
tab bal_goodstockstrat
label var bal_goodstockstrat "Determine stock based on a good strategy"

//Never Visit competitors to check out goods
tab b_visitcompet
gen bal_visitcompet = 1 if b_visitcompet == 7
replace bal_visitcompet = 0 if b_visitcompet != 7
tab bal_visitcompet
label var bal_visitcompet "Never Visit competitors to check prices/quality"

//Never Talk to customers to determine their needs
tab b_customertalk
gen bal_customtalk = 1 if b_customertalk == 6
replace bal_customtalk = 0 if b_customertalk != 6
tab bal_customtalk
label var bal_customtalk "Never Talk to customers to understand their needs"

//Introduced new product based on a good strategy
tab b_im5_adj
gen bal_goodnewstrat = 1 if b_im5_adj == 3
replace bal_goodnewstrat = 0 if b_im5_adj != 3
tab bal_goodnewstrat
label var bal_goodnewstrat "Introduced new products with a good strategy"

//Never do supplier quality comparison
tab b_comparesuppliers
gen bal_qualcomp = 1 if b_comparesuppliers == 7
replace bal_qualcomp = 0 if b_comparesuppliers != 7
tab bal_qualcomp
label var bal_qualcomp "Never do supplier quality comparison"

//Never Negotiate Prices with suppliers
tab b_negotiate
gen bal_negotiate = 1 if b_negotiate == 7
replace bal_negotiate = 0 if b_negotiate != 7
tab bal_negotiate
label var bal_negotiate "Never Negotiated terms with suppliers"

//Ask Suppliers for Better Terms
tab b_askbetterterm
gen bal_betterterms = 1 if b_askbetterterm == 1
replace bal_betterterms = 0 if b_askbetterterm >= 2
tab bal_betterterms
label var bal_betterterms "Successfully Asked suppliers for better terms"

//Take advantage of cash discount
tab b_sm4
gen bal_cashdisc = 1 if b_sm4 == 1
replace bal_cashdisc = 0 if b_sm4 == 0
tab bal_cashdisc
label var bal_cashdisc "Took full advantage of cash discount"

//Do nothing when customers do not pay credit
tab b_donothing
label var b_donothing "Do nothing when customers do not pay credit"


label var b_age "Age"
label var b_gender "Female"
label var b_education_new_3 "Completed High School"
label var b_retailtype_new_2 "Retail: Food"
label var hs_above "High School or Above"
label var b_cc5 "Record Important Customer Credit Information"
label var bal_bus_prime "Business is Primary Source of Income"
label var bal_cashseparate "Do Separate Business & Household Cash"
label var bal_selfsalary "Do Pay Salary to Self"
label var bal_profitcal "Do Calculate Profits"
label var bal_creditdays "Give customers credit for at most 7 days"
label var b_donothing "Do nothing when customers do not pay credit"
label var bal_keeprecord "Keep Business Records "
label var bal_creditrecord "Keep Customer Credit Records"
label var bal_goodstockstrat "Determine stock based on a good strategy"
label var bal_visitcompet "Never Visit competitors to check prices/quality"
label var bal_customtalk "Never Talk to customers to understand needs"
label var bal_qualcomp "Never do supplier quality comparison"
label var bal_negotiate "Never Negotiated terms with suppliers "
label var bal_cashdisc "Took full advantage of cash discount"
label var w1b_salesregwk "Sales-Regular Week (Winsorized at 1%)"
label var w1b_profitregwk "Profits-Regular Week (Winsorized at 1%)"


iebaltab b_age b_gender hs_above bal_bus_prime b_retailtype_new_2 bal_cashseparate bal_selfsalary bal_profitcal bal_creditdays b_donothing bal_keeprecord bal_creditrecord b_cc5 bal_goodstockstrat bal_visitcompet bal_customtalk bal_qualcomp bal_negotiate bal_cashdisc w1b_salesregwk w1b_profitregwk, grpvar(tcarm) savet("$FH/tables/Table 1B.tex") total  rowvarlabels stats(desc(sd) pair(p)) totallabel(Total Sample) grouplabels("0 Control @ 1 Treatment") starlevels(0.1 0.05 0.01) texc("B: Summary Statistics and Balance-India") addnote("Notes: This table presents summary statistics based on baseline survey data. Standard deviations (column 2, 3, 4) of variables and p-values (column 5) appear in parentheses. * Denotes significance at 10%-level, ** at the 5%-level, and *** at the 1%-level") texdoc texn(1.6) nonote
